//
//  GHCollectionHeaderView.m
//  Diary
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 王艺拓. All rights reserved.
//

#import "GHCollectionHeaderView.h"

@interface GHCollectionHeaderView ()

@property (nonatomic, retain) UIView *lineView;

@end

@implementation GHCollectionHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addHeaderViews];
    }
    return self;
}


- (void)addHeaderViews
{
    // 顶部背景图片
    self.bg_image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight * 0.12)];
    self.bg_image.contentMode = UIViewContentModeScaleAspectFill;
    self.bg_image.backgroundColor = [UIColor blackColor];
    self.bg_image.alpha = 0.3;
    //        self.bg_image.autoresizesSubviews = YES;
    //self.bg_image.image = [UIImage imageNamed:@"g"];
    self.bg_image.layer.masksToBounds = YES;
    self.bg_image.userInteractionEnabled= YES;
    [self addSubview:self.bg_image];
    
    CGFloat directionLabelHeight = CGRectGetHeight(self.bg_image.frame) / 2;
    UILabel *directionLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, (CGRectGetHeight(self.bg_image.frame) - directionLabelHeight) / 2, kScreenWidth, directionLabelHeight)];
    directionLabel.text = @"从此部下拉返回桌面,长按日记可删除";
    directionLabel.textColor = [UIColor whiteColor];
    directionLabel.font = [UIFont boldSystemFontOfSize:18];
    directionLabel.textAlignment = NSTextAlignmentCenter;
    [self.bg_image addSubview:directionLabel];
    [self performSelector:@selector(dismissHeaderView) withObject:self afterDelay:2];
    
    // 头像
    //    self.headSculpture = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth/4, kScreenWidth/4)];
    //    self.headSculpture.center = CGPointMake(kScreenWidth / 2, CGRectGetMaxY(self.bg_image.frame));
    //    self.headSculpture.layer.cornerRadius = kScreenWidth / 8;
    //    self.headSculpture.backgroundColor = [UIColor colorWithRed:250 / 255.0 green:199 / 255.0 blue:111 / 255.0 alpha:1];
    //    self.headSculpture.userInteractionEnabled = YES;
    //    //    [self addheadSculptureSubViews];
    //    [self addSubview:self.headSculpture];


//    self.headSculptureButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.headSculptureButton.frame = CGRectMake(0, 0, kScreenWidth/4, kScreenWidth/4);
//    self.headSculptureButton.backgroundColor = [UIColor grayColor];
//    self.headSculptureButton.center = CGPointMake(kScreenWidth / 2, CGRectGetMaxY(self.bg_image.frame));
//    self.headSculptureButton.layer.cornerRadius = kScreenWidth / 8;
//    [self addSubview:self.headSculptureButton];
    
    // 横线
    self.lineView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth * 0.1, kScreenHeight * 0.15, kScreenWidth *0.8, 1)];
    self.lineView.backgroundColor = [UIColor whiteColor];
    self.lineView.alpha = 0.8;
    [self addSubview:_lineView];
    
    // 完成编辑Button
    self.editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.editButton.frame = CGRectMake(kScreenWidth-kScreenHeight*0.1, kScreenHeight*0.05, kScreenHeight*0.1, kScreenHeight*0.05);
    [self.editButton setTitle:@"完成" forState:UIControlStateNormal];
    self.editButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.editButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.editButton.alpha = 0;
    self.editButton.userInteractionEnabled = NO;
    [self addSubview:self.editButton];
    
}


// 适配字体
- (void)fitAutoFont
{
    if ([WYTDevicesTool iPhone320_DEVICES]) {
        self.diarySummaryLabel.font = [UIFont systemFontOfSize:12];
        self.diaryNameLabel.font = [UIFont systemFontOfSize:12];
        self.addressLabel.font = [UIFont systemFontOfSize:14];
        self.dateLabel.font = [UIFont systemFontOfSize:13];
    } else if ([WYTDevicesTool iPhone4_iPhone4s]) {
        self.diarySummaryLabel.font = [UIFont systemFontOfSize:12];
        self.diaryNameLabel.font = [UIFont systemFontOfSize:13];
        self.addressLabel.font = [UIFont systemFontOfSize:14];
        self.dateLabel.font = [UIFont systemFontOfSize:13];
    } else if ([WYTDevicesTool iPhone5_iPhone5s_iPhone5c]) {
        self.diarySummaryLabel.font = [UIFont systemFontOfSize:12];
        self.diaryNameLabel.font = [UIFont systemFontOfSize:13];
        self.addressLabel.font = [UIFont systemFontOfSize:14];
        self.dateLabel.font = [UIFont systemFontOfSize:13];
    } else if ([WYTDevicesTool iPhone6_iPhone6s]) {
        self.diarySummaryLabel.font = [UIFont systemFontOfSize:12];
        self.diaryNameLabel.font = [UIFont systemFontOfSize:13];
        self.addressLabel.font = [UIFont systemFontOfSize:14];
        self.dateLabel.font = [UIFont systemFontOfSize:13];
    } else if ([WYTDevicesTool iPhone6Plus_iPhone6sPlus]) {
        self.diarySummaryLabel.font = [UIFont systemFontOfSize:12];
        self.diaryNameLabel.font = [UIFont systemFontOfSize:13];
        self.addressLabel.font = [UIFont systemFontOfSize:14];
        self.dateLabel.font = [UIFont systemFontOfSize:13];
    } else if ([WYTDevicesTool iPhoneNONE_PLUS]) {
        self.diarySummaryLabel.font = [UIFont systemFontOfSize:12];
        self.diaryNameLabel.font = [UIFont systemFontOfSize:13];
        self.addressLabel.font = [UIFont systemFontOfSize:14];
        self.dateLabel.font = [UIFont systemFontOfSize:13];
    }

}

- (void)dismissHeaderView{
    [UIView animateWithDuration:1 animations:^{
        self.bg_image.alpha = 0;
        self.lineView.frame = CGRectMake(kScreenWidth * 0.1, kScreenHeight * 0.11, kScreenWidth *0.8, 2);
        self.lineView.alpha = 0.5;
    }];
}

@end
